// pages/coldManage/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leaseNum: 0,
    townList: [],

    equipmentList: [],
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 获取出租信息数量
    wx.$req({
      url: `/wms/coldStorage/publishListForApp?page=1&size=1`,
      method: 'post',
    }).then(res => {
      this.setData({ leaseNum: res.data.totalElements })
    })

    // 请求乡镇
    wx.$req({
      url: '/wms/coldStorage/deptIdConditions',
      method: 'post',
    }).then(res => {
      this.setData({ townList: res.data })
    })

    // 请求设备
    wx.$req({
      url: '/wms/coldStorage/installConditions',
      method: 'post',
    }).then(res => {
      const equipmentList = []
      // key转value
      for (let key in res.data) {
        equipmentList.push({
          name: key,
          number: res.data[key]
        })
      }
      this.setData({ equipmentList })
    })

  },

  // 前往出租信息详情页
  toLease (e) {
    let town = e.currentTarget.dataset.town || ''
    let status = e.currentTarget.dataset.status || ''

    let state = ''
    if (status.name === '已安装') {
      state = 0
    } else if (status.name === '未安装') {
      state = 1
    }

    // 注意一下参数需要转换一下
    wx.navigateTo({
      url: `/pages/lease/index?town=${town.id || ''}&status=${state}`
    })
  },

  // 我的出租
  toMyDetail () {
    wx.navigateTo({
      url: '/pages/myLeaseList/index',
    })  
  },

  // 租赁信息
  toMyOtherDetail () {
    wx.navigateTo({
      url: '/pages/myLeaseOtherList/index',
    })  
  }


})